﻿using IdentityServer4;
using IdentityServer4.Models;
using System.Collections.Generic;

namespace EasyShop.IdentityServer.Configuration
{
    public class InMemoryConfiguration
    {
        public static IEnumerable<ApiResource> ApiResources =>
        new ApiResource[]
        {
            new ApiResource("UserService","#UserService")
            {
                Scopes = { "UserService" }
            },
            new ApiResource("OrderService","#OrderService")
            {
                Scopes = { "OrderService" }
            },
            new ApiResource("GoodsService","#GoodsService")
            {
                Scopes = { "GoodsService" }
            },
        };


        public static IEnumerable<Client> Clients()
        {
            return new[]
            {
                  // machine to machine client
                new Client
                {
                    ClientId = "client",
                    ClientSecrets = { new Secret("secret".Sha256()) },

                    AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
                    // scopes that client has access to
                    AllowedScopes = { "UserService", "GoodsService","OrderService" },
                },
                new Client
                {
                    ClientId="vue",
                    ClientName="vue 客户端",
                    AllowedGrantTypes = GrantTypes.Implicit,
                    AllowAccessTokensViaBrowser=true,
                    AccessTokenType = AccessTokenType.Jwt,
                    AllowOfflineAccess=true,
                    RedirectUris = { "http://localhost:8088/callback" },
                    PostLogoutRedirectUris = { "http://localhost:8088/home/index" },
                    AllowedCorsOrigins = { "http://localhost:8088" },

                    AllowedScopes =
                    {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        "UserService",
                        "OrderService",
                        "GoodsService"
                    }
                }
            };
        }
       
        public static IEnumerable<IdentityResource> IdentityResources()
        {
            return new List<IdentityResource>
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile()
            };
        }
        public static IEnumerable<ApiScope> ApiScopes =>
          new ApiScope[] {
                new ApiScope("GoodsService"),
                new ApiScope("OrderService"),
                new ApiScope("UserService")
          };
    }
}
